package com.yonyou.findata.kafka;

import kafka.admin.RackAwareMode;
import kafka.admin.TopicCommand;
import kafka.zk.AdminZkClient;
import kafka.zk.KafkaZkClient;
import kafka.zookeeper.ZooKeeperClient;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.common.utils.Time;
import scala.Option;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author pizhihui
 * @date 2022-01-19 15:57
 */
public class AdminZkClientTest {

    public static void main(String[] args) {

//
//        String zkString = "";
//
//        ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zkString, 3000, 3000, 4000,
//                Time.SYSTEM, "kafka.server", "SessionExpireListener", Option.empty(), Option.empty());
//
//        AdminZkClient adminZkClient = new AdminZkClient(new KafkaZkClient(zooKeeperClient, false, Time.SYSTEM));
//
//        Properties topicConfig = new Properties();
//
//        String topicName = "topic_test_zhihuipi_0119";
//        adminZkClient.createTopic(topicName, 2, 2, topicConfig, RackAwareMode.Enforced, false);



        TopicCommand.main(args);

        Properties commandConfig = new Properties();
        commandConfig.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "10.9.22.23:9092,10.9.22.22:9092,10.9.22.25:9092");
        Admin admin = Admin.create(commandConfig);

//        TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(args);
//        TopicCommand.CommandTopicPartition topic = new TopicCommand.CommandTopicPartition(opts);

        String topicName2 = "topic_test_zhihuipi_0119";
        int partitions = 2;

        NewTopic newTopic = new NewTopic(topicName2, partitions, Short.parseShort("2"));
        Map<String, String> configs = new HashMap<>();
        newTopic.configs(configs);

        try {
            CreateTopicsResult result = admin.createTopics(Collections.singleton(newTopic));
            result.all().get();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
